<?php

use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SvnSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Svns';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="svn-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Create Svn', '#', [
            'id'          => 'create',
            'data-toggle' => 'modal',
            'data-target' => '#create-modal',
            'class'       => 'btn btn-success',
        ]); ?>
    </p>

    <?php Pjax::begin(); ?>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel'  => $searchModel,
        'columns'      => [
            ['class' => 'yii\grid\SerialColumn'],
            // 'patch.title',
            [
                'attribute' => 'title',
                'value'     => 'patch.title',
                'label'     => 'Patch 名称',
            ],
            [
                'attribute' => 'code',
                'value'     => function ($model) {
                    return Html::a($model->code,
                        "https://rs.tkeasia.com/rDT{$model->code}",
                        ['target' => '_blank']);
                },
                'format'    => 'raw',
            ],
            'comment',
            //'environment',
            [
                'attribute' => 'environment',
                'filter'    => $searchModel->environmentList,
                'value'     => function ($data) use ($searchModel) {
                    return $searchModel->getEnvironmentList($data->environment);
                },
            ],
            //'created_at',
            //'updated_at',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

    <?php Pjax::end(); ?>

</div>

<?php
Modal::begin([
    'id'     => 'create-modal',
    'header' => '<h4 class="modal-title">创建</h4>',
]);
Modal::end();
$requestUrl = Url::toRoute('create');
$js = <<<JS
$(document).on('click', '#create', function () {
    $.get('{$requestUrl}', {},
        function (data) {
            $('.modal-body').html(data);
        }  
    );
});
JS;
$this->registerJs($js);